#!/usr/bin/perl
use warnings;
use strict;
our @numbers=qw(1 1 1 1 1 1);
our $r=24;
our @ops=qw(+ - * /);
push @ops,'';
our @o;

sub check {
    my $exp = join "",@o;
    my $result;
    $result =eval($exp);
    print "$exp=$result\n" if($result == $r);
}

sub permutate {
    my $n=shift;
    if($n == @numbers-1){
        $o[2*$n]=$numbers[$n];
        check();
        return;
    }
    for(my $i=0;$i<@ops;$i++){
        $o[2*$n]=$numbers[$n];
        $o[2*$n+1]=$ops[$i]; 
        permutate($n+1);
    }
}

permutate(0);
